package com.aotain.nyx.threateva;

import org.apache.flink.api.common.functions.ReduceFunction;
import org.apache.flink.api.java.tuple.Tuple2;

import com.aotain.nyx.statis.AbnStatisTuple;

public class ThreatenEvaluateReduce implements ReduceFunction<Tuple2<String,AbnStatisTuple>> {

	/** 
	* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么) 
	*/ 
	private static final long serialVersionUID = 8867731776636270995L;

	@Override
	public Tuple2<String, AbnStatisTuple> reduce(
			Tuple2<String, AbnStatisTuple> value1,
			Tuple2<String, AbnStatisTuple> value2) throws Exception {
		// TODO Auto-generated method stub
		AbnStatisTuple tuple = value1.f1;
		if(value1.f1 != null && value2.f1 != null ) {
			String abnormaltype = tuple.getType();
			int eval = 90;
			switch (abnormaltype) {
			case "CC":
				eval = 40;
				break;
			case "BOTS":
				eval = 40;
				break;
			case "SCANATTACK":
				eval = 40;
				break;
			case "SESSIONMIDDLE":
				eval = 80;
				break;
			case "XSS":
				eval = 70;
				break;
			case "PORTLOW":
				eval = 80;
				break;
			case "SYNFLOOD":
				eval = 40;
				break;
			case "UDPFLOOD":
				eval = 40;
				break;
			case "ACKFLOOD":
				eval = 40;
				break;
			case "DNSATTACK":
				eval = 40;
				break;
			case "ICMPFLOOD":
				eval = 40;
				break;
			case "VC":
				eval = 40;
				break;
			case "SENSITIVEURL":
				eval = 70;
				break;
			case "SSRF":
				eval = 70;
				break;
			case "XXE":
				eval = 70;
				break;
			case "DICTRAVERSAL":
				eval = 70;
				break;
			case "TCPFLOOD":
				eval = 70;
				break;
			case "SQLINJECTION":
				eval = 70;
				break;
			default:
				break;
			}
			
			String abnormaltype2 = tuple.getType();
			int eval2 = 90;
			switch (abnormaltype2) {
			case "CC":
				eval2 = 40;
				break;
			case "BOTS":
				eval2 = 40;
				break;
			case "SCANATTACK":
				eval2 = 40;
				break;
			case "SESSIONMIDDLE":
				eval2 = 80;
				break;
			case "XSS":
				eval2 = 70;
				break;
			case "PORTLOW":
				eval2 = 80;
				break;
			case "SYNFLOOD":
				eval2 = 40;
				break;
			case "UDPFLOOD":
				eval2 = 40;
				break;
			case "ACKFLOOD":
				eval2 = 40;
				break;
			case "DNSATTACK":
				eval2 = 40;
				break;
			case "ICMPFLOOD":
				eval2 = 40;
				break;
			case "VC":
				eval2 = 40;
				break;
			case "SENSITIVEURL":
				eval2 = 70;
				break;
			case "SSRF":
				eval2 = 70;
				break;
			case "XXE":
				eval2 = 70;
				break;
			case "DICTRAVERSAL":
				eval2 = 70;
				break;
			case "TCPFLOOD":
				eval2 = 70;
				break;
			case "SQLINJECTION":
				eval2 = 70;
				break;
			default:
				break;
			}
			
			if(eval2-eval<0) {
				tuple.setEvaluate(eval2);
			}else {
				tuple.setEvaluate(eval);
			}
		}else {
			System.out.println("reduce arg is null");
		}
		return new Tuple2<String,AbnStatisTuple>(value1.f0,tuple);
	}

}
